package datastructure.sort.sortmethod;

/**
 * Created by tanlee on 2016/3/18.
 */
public class ShellSort extends BaseSort {


    @Override
    public void sort(Comparable[] a) {
        int length = a.length;
        int h = 1;
        while(h < length/3){
            h = h*3 + 1;
        }
        while(h >= 1){
            for(int i = h;i<length;i++){
                for(int j = i;j>= h&&less(a[j-h],a[j]);j -= h ){
                    exchange(a,j,j-h);
                }
            }
            h = h/3;
        }
    }
}
